package com.tbit.uqbike.client.quartz;


import com.tbit.uqbike.client.constant.SystemData;
import com.tbit.uqbike.client.dao.core.AccountSpikeDao;
import com.tbit.uqbike.client.pojo.AccountSpike;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 禁行区道钉缓存
 *
 * @Author:BUGTian
 * @DATE: 2023/5/30
 */
@Component
@Slf4j
public class AccountSpikeQuartz {

    @Autowired
    private AccountSpikeDao accountSpikeDao;

    @Scheduled(cron = "0 0/1 * * * ?")
    public void refreshAccountSpike() {
        List<AccountSpike> list = accountSpikeDao.getAll();
        Map<String, Integer> map = new ConcurrentHashMap<>();
        for (AccountSpike accountSpike : list) {
            map.put(accountSpike.getAccountId() + "_" + accountSpike.getMac(), accountSpike.getType());
        }
        SystemData.accountSpikeMap = map;
    }
}

